package com.ttc.group2.videochat.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ttc.group2.videochat.R;

public class RecentListAdapter extends ArrayAdapter<String> {

	private Context mContext;
	private int mLayoutId;
	private List<String> baseList;
	private ViewHolder holder;

	public RecentListAdapter(Context context, int resourceId,
			List<String> baseList) {
		super(context, resourceId, baseList);
		this.mContext = context;
		this.mLayoutId = resourceId;
		this.baseList = baseList;
	}

	@Override
	public int getCount() {
		if (baseList != null) {
			return baseList.size();
		}
		return 0;
	}

	@Override
	public String getItem(int position) {
		return baseList.get(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(mLayoutId, parent, false);
			holder = new ViewHolder(convertView);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.bind(getItem(position));
		return holder.mView;
	}

	static class ViewHolder {
		ImageView imgAvatar;
		TextView name;
		TextView message;
		TextView timestamp;
		View mView;

		public ViewHolder(View view) {
			this.mView = view;
			imgAvatar = (ImageView) view.findViewById(R.id.recent_item_icon);
			name = (TextView) view.findViewById(R.id.recent_item_title);
			message = (TextView) view.findViewById(R.id.recent_item_message);
			timestamp = (TextView) view.findViewById(R.id.recent_timestamp);
			mView.setTag(this);
		}

		public void bind(String baseModel) {
			// do stuff - waiting data from server
		}
	}
}
